#  return   返回值

def calc_sum(*args):
    ax = 0
    for n in args:
        ax = ax + n
    return ax

#  返回求和的函数
def lazy_sum(*args):
    def sum():
        ax = 0
        for n in args:
            ax = ax +n
        return ax
    return sum

# 闭包
def count():
    fs = []
    for i in range(1,4):
        def f():
            return i*i
        fs.append(f)
    return fs
f1,f2,f3 = count()

# nonlocal
def inc():
    x =0
    def fn():
        return x+1
    return fn
f  = inc()
print(f())
print(f())


#   闭包返回一个计数器函数，每次调用返回递增函数
def create_counter():
    count=0
    def counter():
        nonlocal count
        count+=1
        return count
    return counter
counter = create_counter()
print(counter())
print(counter())
print(counter())

